﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows;

namespace UtilZ.Dotnet.WindowsDesktopEx.WPF
{
    /// <summary>
    /// WindowChrome显示Margin转换器
    /// </summary>
    public class WindowChromeMarginConverter : ValueConverterAbs
    {
        private static Thickness? _defaultMargin = null;
        /// <summary>
        /// 获取或设置默认Margin,当为未设置默认值(即默认值为null时),转换器采用自动计算
        /// </summary>
        public static Thickness? DefaultMargin
        {
            get { return _defaultMargin; }
            set { _defaultMargin = value; }
        }


        /// <summary>
        /// 构造函数
        /// </summary>
        public WindowChromeMarginConverter()
            : base()
        {

        }

        /// <summary>
        /// 内存对象中转换到显示
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Thickness? defaultMargin = _defaultMargin;
            if (defaultMargin != null)
            {
                return defaultMargin.Value;
            }

            const double OFFSET = 6;
            double left = SystemParameters.WorkArea.Left + OFFSET;
            double top = SystemParameters.WorkArea.Top + OFFSET;
            double right = SystemParameters.PrimaryScreenWidth - SystemParameters.WorkArea.Width + OFFSET;
            double bottom = SystemParameters.PrimaryScreenHeight - SystemParameters.WorkArea.Height + OFFSET;
            return new Thickness(left, top, right, bottom);
        }
    }
}
